#include <QCoreApplication>
#include <QDebug>
#include "../network/TcpServer.h"

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    
    qDebug() << "开始TCP服务器测试...";
    
    TcpServer server;
    
    QObject::connect(&server, &TcpServer::serverStarted, [](const QString &address, int port) {
        qDebug() << QString("服务器启动成功: %1:%2").arg(address).arg(port);
    });
    
    QObject::connect(&server, &TcpServer::serverError, [](const QString &error) {
        qDebug() << "服务器错误:" << error;
    });
    
    QObject::connect(&server, &TcpServer::clientConnected, [](const QString &address, int port) {
        qDebug() << QString("客户端连接: %1:%2").arg(address).arg(port);
    });
    
    if (server.startServer(8888)) {
        qDebug() << "TCP服务器启动命令执行成功";
    } else {
        qDebug() << "TCP服务器启动命令执行失败";
        return -1;
    }
    
    qDebug() << "服务器状态:" << (server.isRunning() ? "运行中" : "已停止");
    qDebug() << "等待客户端连接...";
    qDebug() << "按 Ctrl+C 停止服务器";
    
    return app.exec();
}